package com.attendance.controller;


import com.attendance.common.CommonResult;
import com.attendance.pojo.Admin;
import com.attendance.pojo.Student;
import com.attendance.pojo.Teacher;
import com.attendance.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * 用户管理控制层
 * */
@RestController//声明该类是返回的数据 无需在在方法上面加@ResponseBody
@RequestMapping("/user")
public class UserController {

    //注入用户管理业务
    @Autowired
    private UserService userService;

    /**
     * 管理员登录
     **/
    @PostMapping("/admin/login")
    public CommonResult adminLogin(@RequestBody Admin admin){
        return userService.adminLogin(admin.getAdmAccount(), admin.getAdmPassword());
    }

    /**
     * 老师登录
     * */
    @PostMapping("/teacher/login")
    public CommonResult teacherLogin(@RequestBody Teacher teacher){
        return userService.teacherLogin(teacher.getWorkNumber(), teacher.getTeaPwd());
    }

    /**
     * 学生登录
     * */
    @PostMapping("/student/login")
    public CommonResult studentLogin(@RequestBody Student student){
        return userService.studentLogin(student.getStuNum(),student.getStuPwd());
    }

    /**
     * 管理员修改密码
     * */
    @PutMapping("/admin/updatePw")
    public CommonResult adminUpdatePw(@RequestBody Admin admin){
        return userService.adminUpdatePw(admin.getAdmAccount(), admin.getAdmPassword());
    }

    /**
     * 教师修改密码
     * */
    @PutMapping("/teacher/updatePw")
    public CommonResult teacherUpdatePw(@RequestBody Teacher teacher){
        return userService.teacherUpdatePw(teacher.getWorkNumber(), teacher.getTeaPwd());
    }

    /**
     * 学生修改密码
     * */
    @PutMapping("/student/updatePw")
    public CommonResult studentUpdatePw(@RequestBody Student student){
        return userService.studentUpdatePw(student.getStuNum(), student.getStuPwd());
    }



}
